/*
 * @Author: your name
 * @Date: 2021-11-27 10:11:24
 * @LastEditTime: 2021-12-07 16:49:08
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \toutiao-m\src\api\user.js
 */
import request from '@/utils/request.js'

export function getCode (mobile) {
  return request({
    url: '/v1_0/sms/codes/' + mobile
  })
}

/**
 *
 * @param {*} data {mobile ，code}
 * @returns
 */
export function login (data) {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data
  })
}

/**
 *
 * @param {*} token 获取koken值

 */
export function getUserSelInfo () {
  return request({
    url: '/v1_0/user'
  })
}

/**
 * 获取用户频道信息
 */
export function getUserSelChannels () {
  return request({
    url: '/v1_0/user/channels'
  })
}

/**
 * 获取频道信息
 */
export function addUserChannelItem (channel) {
  return request({
    url: '/v1_0/user/channels',
    method: 'PATCH',
    data: {
      channels: [channel]
    }
  })
}
export function removeUserChannelItem (id) {
  return request({
    url: '/v1_0/user/channels/' + id,
    method: 'DELETE'
  })
}

// 取消关注用户
export function deleteUser (target) {
  return request({
    url: '/v1_0/user/followings/' + target,
    method: 'DELETE'
  })
}

// 关注用户
export function followUser (target) {
  return request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target: target
    }
  })
}

// 获取用户个人资料
export function getUser () {
  return request({
    url: '/v1_0/user/profile'

  })
}

// 更新用户个人昵称
export function UpdateUserProfile (data) {
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data
  })
}

// 更新用户个人头像
export function updateUserPhoto (data) {
  return request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  })
}
